// import storage from '@/utils/storage'
import { sendSocketMsg, init, closeSock } from '@/utils/websocket'
const websocket = {
  state: {
    // 当前终端平台
	socketTask: null,
	initToken: 'f5aaa502-ca7b-1586-b668-00c278d6e75d',
	wsUrl: 'wss://192.168.1.14:7272/wss',
	webSocketList: {
		bizType: null,
		content: '',
		id: '',
		remindLevel: 0,
		senderId: null,
		type: 1,
		userId: null
	},
	connectState: false
  },

  mutations: {
    SET_SOCKETTACK: (state, value) => {
        state.socketTask = value
    },
	SET_SOCKETLIST: (state, value) => {
		state.webSocketList = value
	},
	SET_CONNECTSTATE: (state, value) => {
		state.connectState = value
	}
  },

  actions: {
    connectSocket({ commit }, mark) {
		let that = this;
		init()
		// return new Promise((resolve, reject) => {
		//   LoginApi.login({ form: data })
		//     .then(response => {
		//       const result = response.data
		//       loginSuccess(commit, result)
		//       resolve(response)
		//     })
		//     .catch(reject)
		// })
	},
	handleConnectState({ commit }, res) {
		console.log('是否websocket',res)
		commit('SET_CONNECTSTATE', res)
	},
	 // 获取消息websocket
	handleData ({ commit }, res) {
		console.log('websocket handleData',res)
		// let data = Object.assign(this.webSocketList,res)
		commit('SET_SOCKETLIST', res)
	},
	//发送消息
	sendSocketMessage({ commit },msg) {
		console.log('发送信息')
		console.log(msg)
		sendSocketMsg(msg)
	},
	// 退出登陆关闭websocket
    LogoutWebsocket({ commit }, data) {
		const store = this
		return new Promise((resolve, reject) => {
		  closeSock({activeClose: true, isclose: true})
		  resolve()
		})
	}
  }
}

export default websocket